<?php
namespace app\index\Validate;


use think\Validate;

class MemberValidate extends Validate
{
    protected $rule = [
        'oldpasswd'=>'require',
        'passwd'=>'require|length:6,18|alphaDash',
        'repassword'=>'require|confirm:passwd',
        'realname'=>'require',
        'idcard'=>'require',
        'pay_img'=>'fileExt:jpg,png,jpeg|fileSize:2048000',
        'amount'=>'require|checkAmount',
        'coin_id'=>'require',
        'name'=>'require',
        'address'=>'require',
        'id'=>'require',
    ];

    protected $message = [
        "oldpasswd.require" => "旧密码必填",
        "passwd.require" => "新密码必填",
        "passwd.length" => "新密码长度6-18位",
        "passwd.alphaDash"=>'新密码必须是数字字母下划线组成',
        "repassword.require" => "确认密码必填",
        "repassword.confirm" => "两次密码不一致",
        'pay_img.fileExt'=>'充值截图必须是jpg,png,jpeg',
        'pay_img.fileSize'=>'图片不能超过2M',
        'amount.require'=>'充值金额必填',
        'name.require'=>"充值名称必须填写",
        'address.require'=>"充值地址必须填写",
        'amount.checkAmount'=>'充值金额必须是数字',
        'coin_id.require'=>'充值币种必须选择',
        'id.require'=>'地址id必须填写'
    ];

    protected $scene = [
        'changePasswd' => ["oldpasswd","passwd","repassword"],
        'setWithdrawPasswd' => ["passwd","repassword"],
        'certificate'=>['realname','idcard'],
        'pay'=>['pay_img','amount','coin_id'],
        'add-address'=>['name','coin_id','address'],
        'address-delete'=>['id'],
        'address-set'=>['id'],
        'address-edit'=>['name','coin_id','address','id'],
    ];

    public function checkAmount($value)
    {
        $value = floatval($value);
        if (!is_numeric($value)) {
            return false;
        }
        if ($value<0) {
            return false;
        }
        return true;
    }
}